package org.cy.spring.learning.rpc.discover;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * create date: 2019/10/18 15:47
 *
 * @author cao.yong
 */
public class LocalDefaultServiceRegistry implements ServiceRegistry {

    private ConcurrentMap<String, ServiceDefinition> services = new ConcurrentHashMap<>(0);

    @Override
    public void register(String serviceName, Object object) {
        ServiceDefinition definition = new ServiceDefinition();
        definition.setName(serviceName);
        definition.setInstance(object);
        services.put(serviceName, definition);
    }

    @Override
    public void unregister(String serviceName) {
        services.remove(serviceName);
    }

    @Override
    public ServiceDefinition getService(String serviceName) {
        return services.get(serviceName);
    }
}
